using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Campus
{
    public abstract class BaseEntity : Sprite
    {
        protected int m_currentHP;
        public int CurrentHP
        {
            get { return m_currentHP; }
        }

        protected int m_maxHP;
        public int MaxHP
        {
            get { return m_maxHP; }
        }

        protected String m_name;
        public String Name
        {
            get { return m_name; }
            set { m_name = value; }
        }

        protected bool m_isSelected;
        public bool IsSelected
        {
            get { return m_isSelected; }
            set { m_isSelected = value; }
        }

        protected bool m_isUsable;
        public bool IsUsable {
            get { return m_isUsable; }
            set { m_isUsable = value; }
        }

        protected int m_teamNumber;
        public int TeamNumber
        {
            get { return m_teamNumber; }
            set { m_teamNumber = value; }
        }

        private Player m_owner;
        public Player Owner {
            get { return m_owner; }
        }

        protected float m_constructTime = 2000;

        public BaseEntity(Texture2D texture, Vector2 position, int maxHitPoints, Player owner,
                List<Ability> abilities, List<AbilitySubMenu> subMenus)
            : base(texture, position) {
            m_sprite.Position = position;
            m_maxHP = m_currentHP = maxHitPoints;
            m_owner = owner;
            m_abilities = abilities;
            m_subMenus = subMenus;
        }

        public BaseEntity(Animation animation, Vector2 position, int maxHitPoints, Player owner, 
                List<Ability> abilities, List<AbilitySubMenu> subMenus) : base(animation, position) {
            m_sprite.Position = position;
            m_maxHP = m_currentHP = maxHitPoints;
            m_owner = owner;
            m_abilities = abilities;
            m_subMenus = subMenus;
        }

        public BaseEntity(TextureMapAnimation animation, Vector2 position, int maxHitPoints, Player owner,
                List<Ability> abilities, List<AbilitySubMenu> subMenus)
            : base(animation, position) {
            m_sprite.Position = position;
            m_maxHP = m_currentHP = maxHitPoints;
            m_owner = owner;
            m_abilities = abilities;
            m_subMenus = subMenus;
        }

        public void TakeDamage(int damage)
        {
            m_currentHP -= damage;
            if (m_currentHP <= 0)
            {
                Destroy();
            }
        }

        //TODO: add ability / status stuff
        public void Update(GameTime gameTime, bool checkInput, bool updateBoundingBox)
        {
            base.Update(gameTime, checkInput, updateBoundingBox);
        }

        abstract protected void Destroy();
        override abstract public String ToString();

        private List<Ability> m_abilities;
        public Array Abilities {
            get { return m_abilities.ToArray(); }
        }

        private List<AbilitySubMenu> m_subMenus;
        public Array SubMenus {
            get { return m_subMenus.ToArray(); }
        }
    }
}